class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


class Solution:
    def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
        head = ListNode(0)
        now_note = head
        while l1 or l2:
            if l2 is None or (l1 is not None and l1.val < l2.val):
                now_note.next, l1 = l1, l1.next
            else:
                now_note.next, l2 = l2, l2.next
            now_note = now_note.next
        return head.next
